﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
using Assist;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;

namespace LightSmokeTemperatureCameraAdjust
{
	public partial class ElementAdjustForm : System.Windows.Forms.Form
	{
		public ElementAdjustForm()
		{
			this.InitializeComponent();
		}

		internal FormData FormDataSaver
		{
			get
			{
				return this.m_formData;
			}
			private set
			{
				this.m_formData = value;
			}
		}

		private void btnOK_Click(object sender, EventArgs e)
		{
			if (this.chkLight.Checked)
			{
                this.FormDataSaver.m_lstStrCategory.Add((Autodesk.Revit.DB.BuiltInCategory)(-2001120));
			}
			if (this.chkSmoke.Checked)
			{
                this.FormDataSaver.m_lstStrCategory.Add((Autodesk.Revit.DB.BuiltInCategory)(-2008085));
			}
			if (this.chkCamera.Checked)
			{
                this.FormDataSaver.m_lstStrCategory.Add((Autodesk.Revit.DB.BuiltInCategory)(-2008079));
			}
			if (this.radFloor.Checked)
			{
				this.FormDataSaver.m_bIsSelectOrProject = false;
			}
			else
			{
				this.FormDataSaver.m_bIsSelectOrProject = true;
			}
			if (this.radSingleSelect.Checked)
			{
				this.FormDataSaver.m_bIsSelectOrProject = true;
			}
			else
			{
				this.FormDataSaver.m_bIsSelectOrProject = false;
			}
			base.Close();
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private void LightSmokeTemperatureCameraAdjustForm_Load(object sender, EventArgs e)
		{
			base.Icon = Resource.YArchitechIcon;
			this.chkLight.Checked = true;
			this.radFloor.Checked = true;
			this.radSingleSelect.Checked = true;
			this.ReadDlgData();
		}

		private void SaveDlgData()
		{
			FileStream fileStream = new FileStream(AssistFunc.GetAppRootPath() + "\\Data\\" + "LightSmokeTemperatureCameraAdjustForm.xml", FileMode.Create);
			StreamWriter streamWriter = new StreamWriter(fileStream);
			streamWriter.WriteLine(this.chkLight.Checked);
			streamWriter.WriteLine(this.chkSmoke.Checked);
			streamWriter.WriteLine(this.chkCamera.Checked);
			streamWriter.WriteLine(this.radFloor.Checked);
			streamWriter.WriteLine(this.radCeil.Checked);
			streamWriter.WriteLine(this.radSingleSelect.Checked);
			streamWriter.WriteLine(this.radSelectProject.Checked);
			streamWriter.WriteLine(base.Location.X);
			streamWriter.WriteLine(base.Location.Y);
			streamWriter.Flush();
			streamWriter.Close();
			fileStream.Close();
		}

		private bool ReadDlgData()
		{
			string path = AssistFunc.GetAppRootPath() + "\\Data\\" + "LightSmokeTemperatureCameraAdjustForm.xml";
			if (!File.Exists(path))
			{
				base.StartPosition = FormStartPosition.CenterScreen;
				return true;
			}
			base.StartPosition = FormStartPosition.Manual;
			FileStream fileStream = new FileStream(path, FileMode.Open);
			StreamReader streamReader = new StreamReader(fileStream);
			streamReader.BaseStream.Seek(0L, SeekOrigin.Begin);
			this.chkLight.Checked = streamReader.ReadLine().ToBool(false);
			this.chkSmoke.Checked = streamReader.ReadLine().ToBool(false);
			this.chkCamera.Checked = streamReader.ReadLine().ToBool(false);
			this.radFloor.Checked = streamReader.ReadLine().ToBool(false);
			this.radCeil.Checked = streamReader.ReadLine().ToBool(false);
			this.radSingleSelect.Checked = streamReader.ReadLine().ToBool(false);
			this.radSelectProject.Checked = streamReader.ReadLine().ToBool(false);
			try
			{
				int x = Convert.ToInt32(streamReader.ReadLine());
				int y = Convert.ToInt32(streamReader.ReadLine());
				base.Location = new System.Drawing.Point(x, y);
			}
			catch (Exception)
			{
				streamReader.Close();
				fileStream.Close();
				return true;
			}
			streamReader.Close();
			fileStream.Close();
			return true;
		}

		private void LightSmokeTemperatureCameraAdjustForm_FormClosing(object sender, FormClosingEventArgs e)
		{
			this.SaveDlgData();
		}

		private void radFloor_CheckedChanged(object sender, EventArgs e)
		{
			this.FormDataSaver.m_bIsCeilOrFloor = false;
		}

		private void radCeil_CheckedChanged(object sender, EventArgs e)
		{
			this.FormDataSaver.m_bIsCeilOrFloor = true;
		}

		private void radSingleSelect_CheckedChanged(object sender, EventArgs e)
		{
			this.FormDataSaver.m_bIsSelectOrProject = true;
		}

		private void radSelectProject_CheckedChanged(object sender, EventArgs e)
		{
			this.FormDataSaver.m_bIsSelectOrProject = false;
		}

		private FormData m_formData = new FormData();
	}
}
